package com.jyh.service.basicBi;


import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jyh.config.BaseAction;
import com.jyh.db.dao.BiDataStatisticsDao;
import com.jyh.db.entity.JyhBasicData;
import com.jyh.db.entity.JyhBasicDataExample;
import com.jyh.db.mapper.JyhBasicDataMapper;
import com.jyh.util.Utils;

@Service
public class BasicService extends BaseAction {
	@Autowired
	private BiDataStatisticsDao statisticsDao;
	@Autowired
	private JyhBasicDataMapper dataMapper;
	/**
	 * 数据查找
	 * @param time
	 * @return
	 */
	public JyhBasicData oldServe(String time){
		JyhBasicData vo = new JyhBasicData();
		vo.setTimes(time);
		/*注册人数*/
		String registration_num = Utils.getStrforIn( statisticsDao.getTheRegistrationUser(time));
		/*借款笔数*/
		String loan_num = Utils.getStrforIn(statisticsDao.getFrequencyBorrowing(time));
		/*放款笔数-放款金额*/
		Map<String,Object> creditMap = statisticsDao.getLoanData(time);
		String creditNum = Utils.getStrforIn(creditMap.get("countId")+"");
		String creditMoney = Utils.getStrforIn(creditMap.get("sumMoney")+"");
		/*驳回笔数*/
		String reject_num = Utils.getStrforIn( statisticsDao.getDismissNumber(time));
		/*逾期笔数-逾期金额*/
		Map<String,Object> overdueMap = statisticsDao.getOverdueData(time);
		String overdueNum = Utils.getStrforIn(overdueMap.get("countId")+"");
		String overdueMoney = Utils.getStrforIn(overdueMap.get("sumMoney")+"");
		
		vo.setRegistrationNum(registration_num);
		vo.setLoanNum(loan_num);
		vo.setCreditNum(creditNum);
		vo.setCreditMoney(creditMoney);
		vo.setRejectNum(reject_num);
		vo.setOverdueNum(overdueNum);
		vo.setOverdueMoney(overdueMoney);
		/*放款笔数/借款笔数*/
		vo.setPassingRate(Utils.getMathematicsTo100(creditNum, loan_num)+"%");
		/*驳回笔数/借款笔数*/
		vo.setRejectRate(Utils.getMathematicsTo100(reject_num, loan_num)+"%");
		return vo;
	}
	
	/**
	 * 历史数据查询
	 * @param time1
	 * @param time2
	 * @return
	 */
	public List<JyhBasicData> ListOldData(String time1 ,String time2){
		JyhBasicDataExample example = new JyhBasicDataExample();
		example.createCriteria().andTimesBetween(time1, time2);
		example.setOrderByClause("id desc");
		List<JyhBasicData> list = dataMapper.selectByExample(example);
		return list;
	}
	
}
